package jnpf.engine.custom.request;

/**
 * @author LoveMyOrange
 * @create 2022-08-07 13:44
 */

import jnpf.engine.util.FlowContextHolder;
import lombok.extern.slf4j.Slf4j;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * @author 01
 * @program wrapper-demo
 * @description 替换HttpServletRequest
 * @create 2018-12-24 21:04
 * @since 1.0
 **/
@Slf4j
public class ReplaceStreamFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("StreamFilter初始化...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest requestWrapper = new CustomRequestWrapper((HttpServletRequest) request);
        chain.doFilter(requestWrapper, response);
        FlowContextHolder.removeNodeUser();
        FlowContextHolder.removeTemplateJson();
        FlowContextHolder.removeNodeFormData();
        FlowContextHolder.clearAll();
        FlowContextHolder.removeMultiNodeUserIds();
        FlowContextHolder.removeProcessInstanceIds();
        FlowContextHolder.removeFlowModel();
        FlowContextHolder.removeInterfaceModel();
    }

    @Override
    public void destroy() {
        log.info("StreamFilter销毁...");
    }
}
